package com.cskaoyan.crud;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/10/08 10:04
 *
 * @author ciggar
 */
public class JDBCDeleteDemo {

    public static void main(String[] args) throws SQLException {

        // 1. 注册驱动
        DriverManager.registerDriver(new Driver());

        // 2. 获取连接 (返回的应该是接口的实现类的实例对象 )(com.mysql.jdbc.JDBC4Connection)
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/45th?characterEncoding=utf8&useSSL=false","root","123456");


        // 3. 获取statement对象
        Statement statement = connection.createStatement();


        // 4. 执行sql语句
        int affectedRows = statement.executeUpdate("delete from stu where id > 2000");

        // 5. 解析结果
        System.out.println("affectedRows:" + affectedRows);


        // 6. 断开连接
        statement.close();
        connection.close();
    }
}
